/*
 * Copyright (C) 2010-2014 Enrique Lara (enrique.posix2.lara@gmail.com)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package app.transittool.util;

public final class Log {
    private static final boolean USE_MOCK = Constants.DEBUG;

    private Log() {
    }

    public static void v(final String tag, final String msg) {
        if (USE_MOCK) {
            System.out.println(tag + ":" + msg);
        } else {
            android.util.Log.v(tag, msg);
        }
    }

    public static void v(final String tag, final String msg, final Throwable t) {
        if (USE_MOCK) {
            System.out.println(tag + ":" + msg);
            t.printStackTrace();
        } else {
            android.util.Log.v(tag, msg, t);
        }
    }

    public static void d(final String tag, final String msg) {
        if (USE_MOCK) {
            System.out.println(tag + ":" + msg);
        } else {
            android.util.Log.d(tag, msg);
        }
    }

    public static void d(final String tag, final String msg, final Throwable t) {
        if (USE_MOCK) {
            System.out.println(tag + ":" + msg);
            t.printStackTrace();
        } else {
            android.util.Log.d(tag, msg, t);
        }
    }

    public static void i(final String tag, final String msg) {
        if (USE_MOCK) {
            System.out.println(tag + ":" + msg);
        } else {
            android.util.Log.i(tag, msg);
        }
    }

    public static void i(final String tag, final String msg, final Throwable t) {
        if (USE_MOCK) {
            System.out.println(tag + ":" + msg);
            t.printStackTrace();
        } else {
            android.util.Log.i(tag, msg, t);
        }
    }

    public static void w(final String tag, final String msg) {
        if (USE_MOCK) {
            System.out.println(tag + ":" + msg);
        } else {
            android.util.Log.w(tag, msg);
        }
    }

    public static void w(final String tag, final String msg, final Throwable t) {
        if (USE_MOCK) {
            System.out.println(tag + ":" + msg);
            t.printStackTrace();
        } else {
            android.util.Log.w(tag, msg, t);
        }
    }

    public static boolean isDebugEnabled(final String tag) {
        return isLoggable(tag, android.util.Log.DEBUG);
    }

    public static boolean isLoggable(final String tag, final int level) {
        if (USE_MOCK) {
            return true;
        } else {
            return android.util.Log.isLoggable(tag, level);
        }
    }

    public static void w(final String tag, final Throwable t) {
        if (USE_MOCK) {
            System.out.println(tag + ":Throwable");
            t.printStackTrace();
        } else {
            android.util.Log.w(tag, t);
        }
    }

    public static void e(final String tag, final String msg) {
        if (USE_MOCK) {
            System.out.println(tag + ":" + msg);
        } else {
            android.util.Log.e(tag, msg);
        }
    }

    public static void e(final String tag, final String msg, final Throwable t) {
        if (USE_MOCK) {
            System.out.println(tag + ":" + msg);
            t.printStackTrace();
        } else {
            android.util.Log.e(tag, msg, t);
        }
    }

    public static String getStackTraceString(final Throwable t) {
        if (USE_MOCK) {
            return "";
        } else {
            return android.util.Log.getStackTraceString(t);
        }
    }

    public static void println(final int level, final String tag, final String msg) {
        if (USE_MOCK) {
            System.out.println(tag + ":" + msg);
        } else {
            android.util.Log.println(level, tag, msg);
        }
    }
}
